#pragma once

#include <iostream>
#include <cstring>
#include <unistd.h>
#include <fcntl.h>

class Util
{
public:
    static bool setNonBlock(int fd)
    {
        int flags = fcntl(fd, F_GETFL);
        if(flags<0)
        {
            std::cout<<"fcntl F_GETFL error: "<<strerror(errno)<<std::endl;
            return false;
        }
        flags |= O_NONBLOCK;
        if(fcntl(fd, F_SETFL, flags)<0)
        {
            std::cout<<"fcntl F_SETFL error: "<<strerror(errno)<<std::endl;
            return false;
        }
        return true;
    }
};